# -*- python -*-
# ex: set syntax=python:
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

def distribute_slaves(slave_numbers, builders, os_ver, pool=None, gce=False,
                      prefix='vm'):
  hostname_format = prefix + '%d-m4' if not gce else 'slave%d-c4'
  return [
    {
      'master': 'TryServerChromiumWin',
      'builder': builders,
      'preferred_builder': (builders[i % len(builders)]
                            if slave_numbers >= builders
                            else None),
      'hostname': hostname_format % number,
      'os': 'win',
      'version': os_ver,
      'bits': '64',
      'pool': pool,
    } for i, number in enumerate(slave_numbers)
  ]


def windows():
  cq_slaves = (range(156, 164) + range(182, 184) + range(196, 199) +
               range(201, 204) + range(227, 229) + range(231, 234) +
               range(235, 252) + range(318, 339) + range(346, 348) +
               range(382, 384) + range(399, 407) + range(422, 425) +
               range(426, 430) + range(497, 504) + range(519, 525) +
               range(610, 640) + range(649, 655) + range(661, 665) +
               range(680, 682) + range(715, 722) + range(750, 782) +
               range(829, 854) + range(964, 969) + range(1210, 1270) +
               [147, 173, 178, 188, 193, 211, 224, 254, 260, 273, 341, 355, 358,
                513, 529])
  cq_builders = [
      'win_chromium_compile_dbg_ng',
      'win_chromium_rel_ng',
      'win_chromium_x64_rel_ng',
      'win_clang',
  ]
  cq_pool = distribute_slaves(cq_slaves, cq_builders, 'win7', 'win_cq')

  # Optional CQ builders. Split in two groups because of disk size.
  # Builders using the same checkout directory are grouped together
  # Number of builds per pool is supposed to be roughly balanced.
  optional_slaves_gn = [166, 171, 176, 177]
  optional_builders_gn = [
      # directory: win_archive
      'win_archive',
      'win_x64_archive',
      # directory: win_upload_clang
      'win_upload_clang',  # Needs to be shorter than 17 chars, crbug.com/600465
  ]

  optional_pool_gn = distribute_slaves(
      optional_slaves_gn, optional_builders_gn, 'win7', 'win_optional_gn')

  optional_slaves_chromium = [181, 185, 186, 187, 192]
  optional_highend_slaves_chromium = [1, 5, 10, 553]
  optional_highend_slaves_chromium_2 = [49]

  optional_builders_chromium = [
    # directory: win
    'win_chromium_compile_rel_ng',
    'win_chromium_dbg_ng',
    'win_chromium_syzyasan_rel',
    'win_mojo',
    'win_optional_gpu_tests_rel',
    # directory: win_clang
    'win_chrome_official',
    # directory: win_nacl_sdk
    'win_nacl_sdk',
    # directory: win_nacl_sdk_build
    'win_nacl_sdk_build',
  ]

  # Findit optional builders on high-end machines for reliable failures.
  optional_builders_chromium_highend = [
    # directory: win
    'win_chromium_variable',
    'win_chromium_variable_clang',
    # directory: win_archive
    'win_chromium_variable_archive',
    # directory: win_chrome
    'win_chromium_variable_chrome',
    # directory: win_webkit
    'win_chromium_variable_webkit_builder',
    'win_chromium_variable_webkit_win7_builder',
    # directory: win_webkit
    'win_chromium_variable_webkit_win7_builder_x64',
    # directory: win_x64
    'win_x64_chromium_variable_builder',
  ]

  # Findit optional builders on high-end machines for flake analysis.
  optional_builders_chromium_highend_2 = [
    'win_chromium_variable_deflake',
  ]

  optional_pool_chromium = distribute_slaves(
      optional_slaves_chromium,
      optional_builders_chromium,
      'win7',
      'win_optional_chromium')

  optional_highend_pool_chromium = distribute_slaves(
      optional_highend_slaves_chromium,
      optional_builders_chromium_highend,
      'win7',
      'win_optional_highend',
      prefix='build')

  optional_highend_pool_chromium_2 = distribute_slaves(
      optional_highend_slaves_chromium_2,
      optional_builders_chromium_highend_2,
      'win7',
      'win_optional_highend_2',
      prefix='build')

  optional_pool = (optional_pool_chromium + optional_highend_pool_chromium +
      optional_highend_pool_chromium_2 + optional_pool_gn)

  win8_slaves = ([115, 168, 722, 798, 799] + range(384, 399) +
      range(408, 422) + range(468, 495) +
      range(724, 738) + range(801, 804))
  win8_builders = [
      'win8_chromium_gn_upload',
      'win10_chromium_x64_rel_ng',
  ]
  win8_pool = distribute_slaves(win8_slaves, win8_builders, 'win8', 'win8')

  win_pgo_slaves = ([44] + range(950, 953))
  win_pgo_builders = [
    'win_pgo',
    'win_pgo_x64',
  ]
  win_pgo_pool = distribute_slaves(win_pgo_slaves, win_pgo_builders, 'win7',
      'win_pgo', prefix='build')

  clang_win_pool = [
    {
      'master': 'TryServerChromiumWin',
      'builder': ['win_clang_dbg',
                  'win_clang_rel',
                  'win_clang_x64_dbg',
                  'win_clang_x64_rel'],
      'hostname': 'vm%d-m4' % number,
      'os': 'win',
      'version': 'win7',
      'bits': '64',
      'pool': 'win_clang',
    } for number in (894, 895, 896)
  ]

  return (
      cq_pool +
      optional_pool +
      win8_pool +
      win_pgo_pool +
      clang_win_pool)


slaves = windows()
